export default class Dep {
  constructor () {
    this.subs = []
  }

  addSub (watcher) {
    if (typeof watcher?.update === 'function') {
      this.subs.push(watcher)
    }
  }

  depend () {
    // Dep.target 为 watcher 实例
    if (Dep.target) {
      this.addSub(Dep.target)
      Dep.target = null
    }
  }

  notify () {
    this.subs.forEach(watcher => {
      watcher.update()
    })
  }
}
